package com.example.dw.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.dw.entity.Sign;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 签到Mapper接口
 * @author system
 * @since 2024-01-01
 */
@Mapper
public interface SignMapper extends BaseMapper<Sign> {

    /**
     * 根据用户ID和日期查询签到记录
     */
    @Select("SELECT * FROM sign WHERE userid = #{userid} AND sign_date = #{signDate}")
    Sign findByUserIdAndDate(@Param("userid") Integer userid, @Param("signDate") String signDate);

    /**
     * 根据用户ID查询签到记录列表
     */
    @Select("SELECT * FROM sign WHERE userid = #{userid} ORDER BY sign_date DESC LIMIT #{offset}, #{limit}")
    List<Sign> findByUserId(@Param("userid") Integer userid, @Param("offset") Integer offset, @Param("limit") Integer limit);

    /**
     * 获取用户签到总数
     */
    @Select("SELECT COUNT(*) FROM sign WHERE userid = #{userid}")
    Integer getSignCount(@Param("userid") Integer userid);
} 